package com.six.action.settings;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.six.biz.IPermissionBiz;
import com.six.biz.impl.settings.IPermissionBizImpl;
import com.six.vo.Permission;

@Namespace("/settings")  
@ParentPackage(value = "settings") 
public class PermissionManagementAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5537731368599564267L;
	private IPermissionBiz permissBiz = new IPermissionBizImpl();//权限业务接口
	private int perid;
	private List<Permission> perList = new ArrayList<Permission>();
	private String optMark;
	private Permission permission;
	
	public int getPerid() {
		return perid;
	}
	public void setPerid(int perid) {
		this.perid = perid;
	}
	public List<Permission> getPerList() {
		return perList;
	}
	public void setPerList(List<Permission> perList) {
		this.perList = perList;
	}
	public String getOptMark() {
		return optMark;
	}
	public void setOptMark(String optMark) {
		this.optMark = optMark;
	}
	public Permission getPermission() {
		return permission;
	}
	public void setPermission(Permission permission) {
		this.permission = permission;
	}
	/**
	 * 权限修改，权限不能修改名称，已经在页面控制，不能添加权限，添加功能已经实现，仅为
	 * 做测试使用
	 */
	@Action(value = "PermissionOptAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/settings/authority_manage.jsp")
			}
	)
	public String optPermissionManagement() throws Exception {
		//保存
		permissBiz.savePermission(permission);
		//更新
//		permissBiz.updatePermission(permission);
		return SUCCESS;
		
	}
	/**
	 * 查询列表
	 */
	@Action(value = "queryPermissionListAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/settings/authority_query.jsp")
			}
	)
	public String queryPermissionListAction() throws Exception {
		perList = permissBiz.findPermissionList(permission.getPermID(), permission.getPermName());
		return SUCCESS;
				
	}
	/**
	 * 查询未被删除的权限
	 */
	@Action(value = "queryPermListForGroup")
	public String queryPermListForGroup() throws Exception {
		return null;
		
	}
	/**
	 * 异步响应查询权限信息
	 */
	@Action(value = "queryPermissionInfoAction")
	public String queryPermissionInfoAction() throws Exception {
		permissBiz.findPermissionById(perid);
		return null;
		
	}
	/**
	 * 删除权限
	 */
	@Action(value = "deletePermissionAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/PermissionManagement.jsp")
			}
	)
	public String deletePermissionAction() throws Exception {
		permissBiz.deletePermission(perid);
		return null;
		
	}
	/**
	 * 恢复权限
	 */
	@Action(value = "revertPermissionAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/PermissionManagement.jsp")
			}
	)
	public String revertPermissionAction() throws Exception {
		permissBiz.revertPermission(perid);
		return null;
		
	}
}
